package com.ac.scum.log.web.model.wechat.mp.service;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class TemplateSendService {

    private final WxMpService wxService;

    public String sendTemplate(String openId, String templateId, List<WxMpTemplateData> templateData) throws WxErrorException {
        return wxService.getTemplateMsgService().sendTemplateMsg(WxMpTemplateMessage.builder()
                .toUser(openId)
                .templateId(templateId)
                .data(templateData)
                .build());
    }
}
